package com.alpha.bom;

import java.util.ArrayList;

/**
 * This class represents a Student object
 * 
 * @author Mishael Mae C. Legaspi
 * @version 1.0
 * @since JDK1.7
 */
public class Student extends User {

	private ArrayList<ExamResponse> examResponses;
	private boolean activated;
	
	/**
	 * This is used to instantiate a student with the given student ID, first name, last name, and activation status.
	 * @param studentId Student's ID number
	 * @param firstName Student's first name
	 * @param lastName Student's last name
	 * @param activated Student's activation status
	 */
	public Student(int userId, String firstName, String lastName, boolean activated){
		this.setUserId(userId);
		this.setFirstName(firstName);
		this.setLastName(lastName);
		this.activated = activated;
		this.setPassword("password");
		this.examResponses = new ArrayList<ExamResponse>();
		this.setUserType("Student");
	}
	
	/**
	 * This is used to instantiate a student with the given student ID.
	 * The student's first and last names are set to blank, while the activation status is set to true.
	 * @param studentId Student's ID number
	 */
	public Student (int studentId){
		this(studentId,"","",true);
	}
	
	/**
	 *  This is used to instantiate a student with the given student ID and activation status.
	 *  The student's first and last names are set to blank.
	 * @param studentId Student's ID number
	 * @param activated Student's activation status
	 */
	public Student(int studentId, boolean activated){
		this(studentId,"","",activated);
	}

	/**
	 * This is used to retrieve the exam responses of the student.
	 * @return The student's exam responses
	 */
	public ArrayList<ExamResponse> getExamResponses() {
		return examResponses;
	}

	/**
	 * This is used to set the exam responses of the student with the one indicated.
	 * @param examResponses Student's exam responses to set
	 */
	public void setExamResponses(ArrayList<ExamResponse> examResponses) {
		this.examResponses = examResponses;
	}

	/**
	 * This is used to retrieve the activation status of the student.
	 * @return The student's activation status
	 */
	public boolean isActivated() {
		return activated;
	}

	/**
	 * This is used to set the activation status of the student with the one indicated.
	 * @param activated Student's activation status to set
	 */
	public void setActivated(boolean activated) {
		this.activated = activated;
	}
	
	
	/**
	 * This searches if the student already has a response in a certain exam
	 * @param examResponse Student's response
	 * @return The student's exam response
	 */
	public ExamResponse searchExamResponse(ExamResponse examResponse){
		if (this.examResponses.indexOf(examResponse)!=-1){
			return this.examResponses.get(this.examResponses.indexOf(examResponse));
		}
		return null;
	}
	
	/**
	 * This allows the student to search the exam with the given exam ID.
	 * @param examId Exam ID number
	 * @return The exam response of the student for the exam with the given exam ID.
	 */
	public ExamResponse searchExamResponse(int examId){
		ExamResponse e = null;
		for(ExamResponse er: this.examResponses){
			if (er!=null){
				if(er.getExam().getExamId()==examId){
					e = er;
				}
			}
		}
		return e;
	}
	
	/**
	 * This allows the student to search the exam with the given exam object.
	 * @param exam Exam object
	 * @return The exam response of the student for the given exam
	 */
	public ExamResponse searchExamResponse(Exam exam){
		return this.searchExamResponse(exam.getExamId());
	}
	
	/**
	 * This adds a student's exam response to his/her exam responses list
	 * @param examResponse Student's exam response
	 * @return True if exam response is successfully added. False if the exam of the exam response is already taken by the student.
	 */
	public boolean addExamResponse(ExamResponse examResponse){
		boolean successful = false;
		if(this.searchExamResponse(examResponse)==null){
			this.examResponses.add(examResponse);
			successful = true;
		}
		return successful;
	}
}
